// pages/service/balance-management/index.js
var api = require("../../../../api.js"),
  app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    actions: [{
      name: '提现到银行卡',
      subname: '提现到默认绑定的银行卡中',
      className: 'action-class',
      loading: false
    },
       {
        name: '提现到支付宝',
        subname: '提现到支付宝余额中',
        className: 'action-class',
        loading: false
      },
      {
        name: '提现到余额',
        subname: '提现到微信余额中',
        className: 'action-class',
        loading: false
      }],
    cancelText: '取消'
  },
  onLoad:function(){
    var that = this;
    that.setData({
      icons: wx.getStorageSync('site') + '/addons/sd_liferuning/tp/public/uploads/background',
    })
  },
  onShow:function(){
    var that = this;
      // TODO 发送请求
      that.setData({
        site:wx.getStorageSync('site')
      })
      app.request({
        url: api.default.Income,
        data: {
          cid: wx.getStorageSync('cash').cid,
        },
        success: function (e) {
          console.log('r',e)
          var data = []
          var price = ''
          that.setData({
            data:e.data,
            price: Number(e.data.res3)+Number(e.data.res1)
          })
        }
      })
      app.request({
        url: api.default.capital,
        method: "POST",
        data: {
          uid: wx.getStorageSync('uid'),
          bid: wx.getStorageSync('bid')
        },
        success: function (e) {
           console.log('res:',e);
          that.setData({
            data: e,
            orderCompletePrice: e.orderCompletePrice.toFixed(2)
          })
        }
      })
  },
  // 开启选择器
  openActionsheet() {
    this.setData({
      'show': true
    });
  },
  // 关闭选择器
  closeActionSheet() {
    this.setData({
      'show': false
    });
  },
  // 根据选择进行调用事件
  clickAction({ detail }) {
    const { index } = detail;
    this.setData({
      [`actions[${index}].loading`]: true,
      actionType: index
    });
    switch (index) {
      case 0: // 0 提现到银行卡
        wx.navigateTo({
          url: '/service/pages/service/withdraw-money/index',
        });
        break;
      case 1: // 1 提现到支付宝
        wx.navigateTo({
          url: '/sd_liferuning/pages/constmer/withdraw-ali/index?type=2',
        });
        break;
      case 2: // 2 提现到余额
        wx.navigateTo({
          url: '/service/pages/service/withdraw-wechat/index',
        });
        break;
    }
    setTimeout(() => {
      this.setData({
        [`show`]: false,
        [`actions[${index}].loading`]: false
      });
    }, 100);
  },
})